package edu.ufop.vaadin.helloworld.dao;


import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.sql.Connection;

import org.openqa.selenium.html5.ResultSet;

import edu.ufop.vaading.helloworld.model.Aluno;
import edu.ufop.vaadin.helloworld.ConnectionFactory;


public class AlunoDao {
	private Connection connection;
	
	public AlunoDao(){
		this.connection = new ConnectionFactory().getConnection();
	}
	
	public boolean insertAluno(Aluno a){
		String sql = "insert into alunos "+ "(nome,matricula)" + "values(?,?)";
		
		try{
			PreparedStatement stmt = connection.prepareStatement(sql);
			
			stmt.setString(1, a.getName());
			stmt.setString(2, a.getMatricula());

			stmt.execute();
			stmt.close();
			
		}catch(SQLException e){
			throw new RuntimeException(e);
			return false;
		}
		return true;
		
		
	}
	public boolean findAluno(String matricula){
		Connection con=new ConnectionFactory().getConnection();
		PreparedStatement stmt = con.prepareStatement("select * from alunos");
		
		ResultSet rs = (ResultSet) stmt.executeQuery();
		
		while(rs.next()){
			if (matricula.equals(rs.getString("matricula"))){
					return true;
			}
			
		}
		
	}
	

}
